package com.geecity.flowable.flowabledemo.controller;

import com.geecity.flowable.flowabledemo.entity.R;
import com.geecity.flowable.flowabledemo.service.DispatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author yuanDing
 * @version 1.0
 * @date 2025-07-09 14:30
 */

@RestController
@RequestMapping("/dispatch")
public class DispatchController {

    @Autowired
    private DispatchService dispatchService;


    /**
     * 服务包派发
     * @param cangKuUuid
     * @return
     */
    @PostMapping
    public R dispatch(@RequestParam("cangKuUuid") String cangKuUuid, MultipartFile file) {
        R result = dispatchService.dispatch(cangKuUuid, file);
        return result;
    }

    /**
     * 获取服务包列表,启停信息
     * @param cangKuUuid
     * @return
     */
    @PostMapping("list")
    public R deploymentMessageList(@RequestParam("cangKuUuid") String cangKuUuid) {
        R result = dispatchService.deploymentMessageList(cangKuUuid);
        return result;
    }


    /**
     * 服务部署
     * @param cangKuUuid
     * @return
     */
    @PostMapping("/deployment")
    public void deployment(@RequestParam("cangKuUuid") String cangKuUuid , @RequestParam("jarName") String jarName , HttpServletResponse response) {
        dispatchService.deployment(cangKuUuid, jarName ,response );
    }

    /**
     * 停止服务
     * @param cangKuUuid 仓库UUID
     * @param jarName 服务包名
     * @return 操作结果
     */
    @PostMapping("/stopService")
    public R stopService(@RequestParam("cangKuUuid") String cangKuUuid, @RequestParam("jarName") String jarName) {
        return dispatchService.stopService(cangKuUuid, jarName);
    }

    @PostMapping("dispatchInner")
    public R dispatchInner(@RequestParam("cangKuUuid") String cangKuUuid, @RequestParam("upgradePackageName") String upgradePackageName) {
        return dispatchService.dispatchInner(cangKuUuid, upgradePackageName);
    }

    /**
     * 获取升级包列表
     * @return
     */
    @GetMapping("upgradeList/{cangKuUuid}")
    public R upgradeList(@PathVariable("cangKuUuid") String cangKuUuid) {
        R result = dispatchService.upgradeList(cangKuUuid);
        return result;
    }

}
